<?php
namespace BP\GPM;
require_once("BP/En/Map.php");
require_once("BP/Sys/FrmType.php");
require_once("BP/Web/WebUser.php");
class Menu extends EntityTree {
	public $IsCheck;	// boolean
	private function __init() { // default class members
		$this->IsCheck =  FALSE ;
	}
	public function getHisUAC () 
	{
		$uac = new UAC();
		if ($WebUser->getNo()->equals("admin"))
		{
			$uac->IsDelete =  TRUE ;
			$uac->IsUpdate =  TRUE ;
			$uac->IsInsert =  TRUE ;
			return $uac;
		}
		else
		{
			$uac->Readonly();
		}
		return $uac;
	}
	public function getCtrlObjs () 
	{
		return $this->GetValStringByKey(MenuAttr::$CtrlObjs);
	}
	public function setCtrlObjs ($value) // [String value]
	{
		$this->SetValByKey(MenuAttr::$CtrlObjs, $value);
	}
	public function getHisMenuType () 
	{
		return MenuType->forValue($this->GetValIntByKey(MenuAttr::$MenuType));
	}
	public function setHisMenuType ($value) // [MenuType value]
	{
		$this->SetValByKey(MenuAttr::$MenuType, $value->getValue());
	}
	public function getIsEnable () 
	{
		return $this->GetValBooleanByKey(MenuAttr::$IsEnable);
	}
	public function setIsEnable ($value) // [boolean value]
	{
		$this->SetValByKey(MenuAttr::$IsEnable, $value);
	}
	public function getOpenWay () 
	{
		$openWay = 0;
		switch ($openWay) {
			case 0:
				return "_blank";
			case 1:
				return $this->getNo();
			default:
				return "";
		}
	}
	public function getMenuType () 
	{
		return MenuType->forValue($this->GetValIntByKey(MenuAttr::$MenuType));
	}
	public function setMenuType ($value) // [MenuType value]
	{
		$this->SetValByKey(MenuAttr::$MenuType, $value->getValue());
	}
	public function getFK_App () 
	{
		return $this->GetValStringByKey(MenuAttr::$FK_App);
	}
	public function setFK_App ($value) // [String value]
	{
		$this->SetValByKey(MenuAttr::$FK_App, $value);
	}
	public function getFlag () 
	{
		return $this->GetValStringByKey(MenuAttr::$Flag);
	}
	public function setFlag ($value) // [String value]
	{
		$this->SetValByKey(MenuAttr::$Flag, $value);
	}
	public function getImg () 
	{
		$s = $this->GetValStringByKey("WebPath");
		if ($DataType->IsNullOrEmpty($s))
		{
			if (($this->getHisMenuType() == MenuType::$Dir))
			{
				return "/Images/Btn/View.gif";
			}
			else
			{
				return "/Images/Btn/Go.gif";
			}
		}
		else
		{
			return $s;
		}
	}
	public function setImg ($value) // [String value]
	{
		$this->SetValByKey("WebPath", $value);
	}
	public function getUrl () 
	{
		return $this->GetValStringByKey(MenuAttr::$Url);
	}
	public function setUrl ($value) // [String value]
	{
		$this->SetValByKey(MenuAttr::$Url, $value);
	}
	public function getUrlExt () 
	{
		return $this->GetValStringByKey(MenuAttr::$UrlExt);
	}
	public function setUrlExt ($value) // [String value]
	{
		$this->SetValByKey(MenuAttr::$UrlExt, $value);
	}
	public function getTag1 () 
	{
		return $this->GetValStringByKey(MenuAttr::$Tag1);
	}
	public function setTag1 ($value) // [String value]
	{
		$this->SetValByKey(MenuAttr::$Tag1, $value);
	}
	public static function constructor__ () 
	{
		$me = new self();
		$me->__init();
		return $me;
	}
	public static function constructor__String ($no) // [String no]
	{
		$me = new self();
		$me->__init();
		$me->setNo($no);
		$me->Retrieve();
		return $me;
	}
	protected function beforeDelete () 
	{
		if (($this->getFlag()->contains("FlowSort") || $this->getFlag()->contains("Flow")))
		{
			throw new \RuntimeException("@删除失败,此项为工作流菜单，不能删除�??");
		}
		return parent->beforeDelete();
	}
	protected function afterDelete () 
	{
		$ens = Menus::constructor__();
		$ens->Retrieve(MenuAttr::$ParentNo, $this->getNo());
		foreach ($ens->ToJavaList() as $item) 		{
			$item->Delete();
		}
		parent->afterDelete();
	}
	public function getEnMap () 
	{
		if (($this->get_enMap() != NULL))
		{
			return $this->get_enMap();
		}
		$map = new Map("GPM_Menu");
		$map->setDepositaryOfEntity($Depositary->None);
		$map->setDepositaryOfMap($Depositary->Application);
		$map->setEnDesc("系统菜单");
		$map->setEnType($EnType->Sys);
		$map->setCodeStruct("4");
		$map->AddTBStringPK(MenuAttr::$No, NULL, "功能编号",  TRUE ,  TRUE , 1, 90, 50);
		$map->AddDDLEntities(MenuAttr::$ParentNo, NULL, $DataType->AppString, "父节�?", Menus::constructor__(), "No", "Name",  FALSE );
		$map->AddTBString(MenuAttr::$Name, NULL, "名称",  TRUE ,  FALSE , 0, 300, 200,  TRUE );
		$map->AddTBInt(MenuAttr::$Idx, 0, "顺序�?",  TRUE ,  FALSE );
		$map->AddDDLSysEnum(MenuAttr::$MenuType, 0, "菜单类型",  TRUE ,  TRUE , MenuAttr::$MenuType, "@0=系统根目录@1=系统类别@2=系统@3=目录@4=功能/界面@5=功能控制�?");
		$map->AddDDLEntities(MenuAttr::$FK_App, NULL, "系统", Apps::constructor__(),  FALSE );
		$map->AddDDLSysEnum(MenuAttr::$OpenWay, 1, "打开方式",  TRUE ,  TRUE , MenuAttr::$OpenWay, "@0=新窗口@1=本窗口@2=覆盖新窗�?");
		$map->AddTBString(MenuAttr::$Url, NULL, "连接",  FALSE ,  FALSE , 0, 3900, 200,  TRUE );
		$map->AddTBString(MenuAttr::$UrlExt, NULL, "连接",  TRUE ,  FALSE , 0, 3900, 200,  TRUE );
		$map->AddBoolean(MenuAttr::$IsEnable,  TRUE , "是否启用?",  TRUE ,  TRUE );
		$map->AddTBString(MenuAttr::$Icon, NULL, "Icon",  TRUE ,  FALSE , 0, 500, 50,  TRUE );
		$map->AddDDLSysEnum(MenuAttr::$MenuCtrlWay, 0, "控制方式",  TRUE ,  TRUE , MenuAttr::$MenuCtrlWay, "@0=按照设置的控制@1=任何人都可以使用@2=Admin用户可以使用");
		$map->AddTBString(MenuAttr::$Flag, NULL, "标记",  TRUE ,  FALSE , 0, 500, 20,  FALSE );
		$map->AddTBString(MenuAttr::$Tag1, NULL, "Tag1",  TRUE ,  FALSE , 0, 500, 20,  TRUE );
		$map->AddTBString(MenuAttr::$Tag2, NULL, "Tag2",  TRUE ,  FALSE , 0, 500, 20,  TRUE );
		$map->AddTBString(MenuAttr::$Tag3, NULL, "Tag3",  TRUE ,  FALSE , 0, 500, 20,  TRUE );
		$map->AddTBInt(MenuAttr::$Idx, 0, "顺序�?",  TRUE ,  FALSE );
		$map->AddMyFile("图标");
		$map->AddSearchAttr(MenuAttr::$FK_App);
		$map->AddSearchAttr(MenuAttr::$MenuType);
		$map->AddSearchAttr(MenuAttr::$OpenWay);
		$map->getAttrsOfOneVSM()->Add(GroupMenus::constructor__(), Groups::constructor__(), GroupMenuAttr::$FK_Menu, GroupMenuAttr::$FK_Group, EmpAttr::$Name, EmpAttr::$No, "绑定到权限组");
		$map->getAttrsOfOneVSM()->Add(StationMenus::constructor__(), Stations::constructor__(), StationMenuAttr::$FK_Menu, StationMenuAttr::$FK_Station, EmpAttr::$Name, EmpAttr::$No, "绑定到岗�?-列表模式");
		$map->getAttrsOfOneVSM()->AddGroupListModel(StationMenus::constructor__(), Stations::constructor__(), StationMenuAttr::$FK_Menu, StationMenuAttr::$FK_Station, "绑定到岗�?-分组模式", StationAttr::$FK_StationType, "Name", EmpAttr::$No);
		$map->getAttrsOfOneVSM()->AddBranchesAndLeaf(EmpMenus::constructor__(), Emps::constructor__(), EmpMenuAttr::$FK_Menu, EmpMenuAttr::$FK_Emp, "绑定人员-树结�?", EmpAttr::$FK_Dept, EmpAttr::$Name, EmpAttr::$No, "@WebUser.getFK_Dept()");
		$rm = new RefMethod();
		$rm->Title = "增加(增删改查)功能权限";
		$rm->Warning = "确定要增加吗�?";
		$rm->ClassMethodName = ($this . ".DoAddRight3");
		$rm->IsForEns =  TRUE ;
		$rm->IsCanBatch =  TRUE ;
		$map->AddRefMethod($rm);
		$rm = new RefMethod();
		$rm->GroupName = "创建菜单(对目录有�?)";
		$rm->Title = "创建单据";
		$rm->Warning = "您确定要创建吗？";
		$rm->getHisAttrs()->AddTBString("No", NULL, "单据编号",  TRUE ,  FALSE , 0, 100, 100);
		$rm->getHisAttrs()->AddTBString("Name", NULL, "单据名称",  TRUE ,  FALSE , 0, 100, 400);
		$rm->getHisAttrs()->AddTBString("PTable", NULL, "存储�?(为空则为编号相同)",  TRUE ,  FALSE , 0, 100, 100);
		$rm->getHisAttrs()->AddDDLSysEnum("FrmType", 0, "单据模式",  TRUE ,  TRUE , "BillFrmType", "@0=傻瓜表单@1=自由表单");
		$rm->getHisAttrs()->AddDDLSQL("Sys_FormTree", "", "选择表单�?", "SELECT No,Name FROM Sys_FormTree WHERE ParentNo='1'",  TRUE );
		$rm->ClassMethodName = ($this . ".DoAddCCBill");
		$map->AddRefMethod($rm);
		$this->set_enMap($map);
		return $this->get_enMap();
	}
	public function DoAddCCBill ($no, $name, $ptable, $frmType, $formTree) // [String no, String name, String ptable, int frmType, String formTree]
	{
		if (($this->getMenuType() != MenuType::$Dir))
		{
			return "err@菜单树的节点必须为目录才能创�?.";
		}
		try 
		{
			if (($frmType == 0))
			{
				CCFormAPI->CreateFrm($no, $name, $formTree, $FrmType->FoolForm);
			}
			else
			{
				CCFormAPI->CreateFrm($no, $name, $formTree, $FrmType->FreeFrm);
			}
			$fb = new FrmBill($no);
			$fb->setNo($no);
			$fb->setName($name);
			$fb->setPTable($ptable);
			$fb->Update();
			$fb->DoBindMenu($this->getNo(), $name);
			return (("<a href='../Comm/En.htm?EnName=BP.Frm.FrmBill&No=" . $no) . "' target=_blank>打开单据属�??</a>.");
		}
		catch (\RuntimeException $ex)
		{
			return ("err@" . $ex->getMessage());
		}
	}
	public function DoAddRight3 () 
	{
		if ((($this->getUrl()->contains("Search.htm") ==  FALSE ) && ($this->getUrl()->contains("SearchBS.htm") ==  FALSE )))
		{
			return "该功能非Search组件，所以您不能增加功能权限.";
		}
		$tempVar = $this->DoCreateSubNode();
		$en = ( ($tempVar instanceof Menu) ? $tempVar : NULL );
		$en->setName("增加权限");
		$en->setMenuType(MenuType::$Function);
		$en->setUrl($this->getUrl());
		$en->setTag1("Insert");
		$en->Update();
		$tempVar2 = $this->DoCreateSubNode();
		$en = ( ($tempVar2 instanceof Menu) ? $tempVar2 : NULL );
		$en->setName("修改权限");
		$en->setMenuType(MenuType::$Function);
		$en->setUrl($this->getUrl());
		$en->setTag1("Update");
		$en->Update();
		$tempVar3 = $this->DoCreateSubNode();
		$en = ( ($tempVar3 instanceof Menu) ? $tempVar3 : NULL );
		$en->setName("删除权限");
		$en->setMenuType(MenuType::$Function);
		$en->setUrl($this->getUrl());
		$en->setTag1("Delete");
		$en->Update();
		return "增加成功,请刷新节�?.";
	}
	public function getWebPath () 
	{
		return $this->GetValStrByKey($EntityNoMyFileAttr->WebPath);
	}
	public function setWebPath ($value) // [String value]
	{
		$this->SetValByKey($EntityNoMyFileAttr->WebPath, $value);
	}
	protected function beforeUpdateInsertAction () 
	{
		$this->setWebPath($this->getWebPath()->replace("//", "/"));
		$this->setUrl($this->getUrlExt());
		return parent->beforeUpdateInsertAction();
	}
	public function DoMyCreateSubNode () 
	{
		$en = $this->DoCreateSubNode();
		$en->SetValByKey(MenuAttr::$FK_App, $this->GetValByKey(MenuAttr::$FK_App));
		$en->Update();
		return $en->ToJson();
	}
	public function DoMyCreateSameLevelNode () 
	{
		$en = $this->DoCreateSameLevelNode();
		$en->SetValByKey(MenuAttr::$FK_App, $this->GetValByKey(MenuAttr::$FK_App));
		$en->Update();
		return $en->ToJson();
	}
}
?>
